package com.app.qtjk.lsh.service;
import com.app.common.dataDictionary.DE.DE_USERPRIZE_ID;
import com.app.common.dataDictionary.DE.DE_USERPRIZE_SFUSED;
import com.app.common.dataDictionary.DE.DE_U_SWDD_ID;
import com.app.common.dataDictionary.DE.DE_U_SWDD_OPPTIME;
import com.app.common.dataDictionary.DE.DE_U_SWDD_SHRDZ;
import com.app.common.dataDictionary.DE.DE_U_SWDD_SHRLXDH;
import com.app.common.dataDictionary.DE.DE_U_SWDD_SHRXM;
import com.app.common.dataDictionary.DE.DE_U_SWDD_SHRYZBM;
import com.app.common.dataDictionary.DE.DE_U_SWDD_STATUS;
import com.app.common.dataDictionary.PO.TUserPrizePO;
import com.app.common.dataDictionary.PO.TUserprizeSwddPO;
import com.app.common.utils.DateFormatUtil;
import com.app.common.utils.ReqJsonUtil;
import com.css.sword.kernel.base.annotation.Service;
import com.css.sword.kernel.base.annotation.ServiceContainer;
import com.css.sword.kernel.base.persistence.IPersistenceService;
import com.css.sword.kernel.utils.SwordLogUtils;
import com.css.sword.kernel.utils.SwordPersistenceUtils;
import com.css.sword.kernel.utils.SwordSequenceUtils;
import com.css.sword.platform.web.event.IReqData;
import com.css.sword.platform.web.event.IResData;
import com.css.sword.platform.web.event.SwordRes;

@ServiceContainer
public class UserprizeOrderService {

	private static SwordLogUtils log = SwordLogUtils.getLogger(UserprizeOrderService.class);

	public UserprizeOrderService() throws Exception {
		super();
	}


	/**
	 * 保存订单
	 * @param req
	 * @return
	 * @throws Exception
	 */
	@Service(serviceName = "UserprizeOrderService_save")
	public IResData save(IReqData req) throws Exception {

		

		log.debug("开始进入 UserprizeOrderService_save 方法。");

		IPersistenceService dao = SwordPersistenceUtils.getPersistenceService();
		dao.getTransactionService().setAutoCommit(false);
		IResData res = new SwordRes();
		boolean status = true;
		try {
			//获取前台post的数据
			String userprizeId = ReqJsonUtil.getPostParam(req, "userprizeId");
			String shrxm = ReqJsonUtil.getPostParam(req, "shrxm");
			String shrdz = ReqJsonUtil.getPostParam(req, "shrdz");
			String shrlxdh = ReqJsonUtil.getPostParam(req, "shrlxdh");
			String shryzbm = ReqJsonUtil.getPostParam(req, "shryzbm");
			//新生成一条订单记录
			TUserprizeSwddPO po = new TUserprizeSwddPO();
			po.setUserprizeId(new DE_USERPRIZE_ID(userprizeId));
			po.setUSwddId(new DE_U_SWDD_ID(SwordSequenceUtils.generateRandomString()));
			po.setUSwddShrxm(new DE_U_SWDD_SHRXM(shrxm));
			po.setUSwddShrlxdh(new DE_U_SWDD_SHRLXDH(shrlxdh));
			po.setUSwddShryzbm(new DE_U_SWDD_SHRYZBM(shryzbm));
			po.setUSwddShrdz(new DE_U_SWDD_SHRDZ(shrdz));
			po.setUSwddStatus(new DE_U_SWDD_STATUS("chz"));
			po.setUSwddOpptime(new DE_U_SWDD_OPPTIME(DateFormatUtil.getNowDate()));
			int i = dao.insertPO(po);
			//修改用户奖品表为已使用
			TUserPrizePO tUserPrizePO = new TUserPrizePO();
			tUserPrizePO.setUserprizeId(new DE_USERPRIZE_ID(userprizeId));
			tUserPrizePO.setUserprizeSfused(new DE_USERPRIZE_SFUSED("chz"));
			int j= dao.updatePO(tUserPrizePO);
			if (i==1 && j==1) {
				dao.commitAll();
			}
		} catch (Exception e) {
			status = false;
			e.printStackTrace();
			log.debug("---------操作异常！---------");
		}
		
		res.put("status", status);
		return res;
	}

	 		
	/**
	 * 得到用户奖品订单详情
	 */
	@Service(serviceName = "UserprizeOrderService_getOrderDetail")
	public IResData getOrderDetail(IReqData req) throws Exception {

		

		log.debug("开始进入 UserprizeOrderService_getOrderDetail 方法。");

		//IPersistenceService dao = SwordPersistenceUtils.getPersistenceService();

		//IPageQueryDAO pdao=PageQueryUtils.getPageQueryDAO(); 

		IResData res = new SwordRes();

		return res;

	}

	 		
	/**
	 * 用户确认收货业务逻辑
	 * @param req
	 * @return
	 * @throws Exception
	 */
	@Service(serviceName = "UserprizeOrderService_confirmSh")
	public IResData confirmSh(IReqData req) throws Exception {

		log.debug("开始进入 UserprizeOrderService_confirmSh 方法。");

		IPersistenceService dao = SwordPersistenceUtils.getPersistenceService();
		IResData res = new SwordRes();
		String uSwddId = ReqJsonUtil.getPostParam(req, "uSwddId");
		String userprizeId = ReqJsonUtil.getPostParam(req, "userprizeId");
		boolean status = false;
		try {
			TUserprizeSwddPO po = new TUserprizeSwddPO();
			po.setUSwddId(new DE_U_SWDD_ID(uSwddId));
			po.setUSwddOpptime(new DE_U_SWDD_OPPTIME(DateFormatUtil.getNowDate()));
			po.setUSwddStatus(new DE_U_SWDD_STATUS("ysh"));
			int i=dao.updatePO(po);
			//修改用户奖品表为已使用
			TUserPrizePO tUserPrizePO = new TUserPrizePO();
			tUserPrizePO.setUserprizeId(new DE_USERPRIZE_ID(userprizeId));
			tUserPrizePO.setUserprizeSfused(new DE_USERPRIZE_SFUSED("ysh"));
			int j= dao.updatePO(tUserPrizePO);
			if (i==1 && j==1) {
				dao.commitAll();
				status = true;
			}
		} catch (Exception e) {
			status = false;
			e.printStackTrace();
			log.debug("---------操作异常！---------");
		}
		
		res.put("status", status);
		return res;
	}

}